document.querySelector('#btn-login').addEventListener('click', async () => {
    const form = document.querySelector('.login-form')
    const data = serialize(form, {empty: true, hash: true})
    const {username, password} = data

    if(username === '' || password === '') {
        showToast('用户名和密码不能为空')
        return
    }
    if (username.length < 8 || username.length > 15 || password.length < 6 || password.length > 15) {
        showToast('用户名长度为8-15，密码长度为6-15')
        return
    }
    try {
        const res = await axios.post('/login', { username, password})
        showToast(res.data.messgae)

        localStorage.setItem('token', res.data.data.token)
        localStorage.setItem('username', res.data.data.username)

        setTimeout(()=>{
            location.href = './index.html'
        },1000)

    } catch (error) {
        showToast(error.response.messgae)
    }
})